local Data "CPI"

noi disp "Obtaining CPI data..."
noi disp "Verifying that `Data'.dta does not already exist..."
* This returns an error if the file does not exist.
capture confirm file `Data'.dta

* If an error is returned, then the commands below are run.
if _rc == 601 {
	noi disp "Data not found.  Building data..."
	noi disp "Loading CPI CPALTT01USA661S.csv..."

	insheet using "$SourceData\CPI CPALTT01USA661S.csv", clear
	keep year cpaltt01usa661s
	keep if year>1997
	gen base = cpaltt01usa661s[4]
	replace cpaltt01usa661s = cpaltt01usa661s/base
	drop base
	sort year
	compress
	save "$LocalData\\`Data'.dta", replace
	save "$LocalData\Archive\\`Data'`CurrentDate'.dta", replace
}
* This runs if no error was returned.
else noi disp "Data already exists."
noi etime
noi disp " "